function switchTab(identify,index,count) {
	for(i=0;i<count;i++) {
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i) ;
		var CurListObj = document.getElementById("List_"+identify+"_"+i) ;
		if (i != index) {
			fRemoveClass(CurTabObj , "upH2") ;
			fRemoveClass(CurListObj , "upBox") ;
		}
	}
	try {
		for (ind=0;ind<CachePic['recommend'][index].length ;ind++ ) {
			var picobj = document.getElementById("recommend_pic_"+index+"_"+ind) ;
			//if (picobj.src == "http://images.movie.xunlei.com/img_default.gif") {
				picobj.src = CachePic['recommend'][index][ind] ;
			//}
		}
	}
	catch (e) {}
	
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH2") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upBox") ;
}

function fAddClass(XEle, XClass) {
  if(!XClass) throw new Error("XClass 不能为空!");
  if(XEle.className!="") {
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = XEle.className.replace(Re, "");
	var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
	if (OldClassName == "" ) {
		 XEle.className = XClass;
	}
	else {
		XEle.className = OldClassName + " " + XClass;
	}
  }
  else XEle.className = XClass;
}

function fRemoveClass(XEle, XClass) {
  if(!XClass) throw new Error("XClass 不能为空!");
  var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
  if(OldClassName!="") {
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = OldClassName.replace(Re, "");
  }
}
var pre_searchtype = "search" ;
function changeSearchType(type) {
	if ($("searchType_"+pre_searchtype)) {
		$("searchType_"+pre_searchtype).className = "" ;
	}
	pre_searchtype = type ;
	$("searchType_"+type).className = "currA" ;
	setResType(type) ;
	if ($("searchbox1").value == '搜索超过10万部影视内容') {
		$("searchbox1").value = "" ;
	}
	else {
		$("searchbox1").value = $("searchbox1").value + "" ;
	}
	$("searchbox1").focus() ;
}
function $(item){
	return document.getElementById(item);
}
//document.domain='xunlei.com';
function c_getCookie(sName){
	var sSearch = sName + "=";
	var iOffset = document.cookie.indexOf(sSearch);
	if (iOffset != -1) {
		iOffset += sSearch.length;
		var iEnd = document.cookie.indexOf(";", iOffset);
		if (iEnd == -1)
			iEnd = document.cookie.length;
		return unescape(document.cookie.substring(iOffset, iEnd));
	}else 
		return "";
}
function c_setCookie(sName,sValue,sHours){
	if(arguments.length>2){
		var expireDate=new Date(new Date().getTime()+sHours*3600000);
		document.cookie = sName + "=" + escape(sValue) + "; path=/; domain=xunlei.com; expires=" + expireDate.toGMTString();
	}else
		document.cookie = sName + "=" + escape(sValue) + "; path=/; domain=xunlei.com"; 
}
function c_login(u){
	top.location='http://i.xunlei.com/account/login.html?url='+encodeURIComponent(u);
}
function c_logout(o){
	c_setCookie("sessionid","");
	o.innerHTML='<a href="javascript:c_login(top.location);"> 登录 </a><a href="javascript:c_regist(top.location);"> 注册 </a>';
}
function c_regist(u){
	top.location='http://i.xunlei.com/account/signup2.shtml?url='+encodeURIComponent(u);
}
function c_verfySession(o){
	if(c_getCookie('sessionid')!=''){
		o.innerHTML='<a href="javascript:;">'+c_getCookie('nickname')+'('+c_getCookie('usrname')+')</a><a  href="javascript:c_logout('+o.id+');" >退出  </a>';
	}
}
//页面登录信息初始化
function initLogininfo()
{
	 var headDiv = $("div_userinfo");
	 if(headDiv){
		c_verfySession(headDiv);
	 }
}
function doLoginOut(){
	 var headDiv = $("div_userinfo");
	 if(headDiv){
		c_logout(headDiv);
	 }
}
//向左滚动
ScrollCrossLeft={interval:0,count:0,duration:0,step:0,srcObj:null,callback:null};
ScrollCrossLeft.doit=function(obj,b,c,d){
	var s=ScrollCrossLeft;
	obj.style.marginLeft=cpu(s.count,b,c,d)+'px';
	s.count++;
	if(s.count==d){
		clearInterval(s.interval);
		s.count=0;
		obj.style.marginLeft=b+c+'px';
		s.callback();
	}
	function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;};
}
ScrollCrossLeft.scroll=function(obj,step,span,beign,callback,duration){
	var s=ScrollCrossLeft;
	s.duration=duration;
	s.callback=callback;
	s.interval=setInterval(function(){s.doit(obj,beign,step*span,duration)},10);
}
//首页
var HotPlay={current:0,step:468,a:'a_hp_',div:'div_hp_content',ul:'ul_hp',clickflag:0}
var Movie_red={current:0,step:230,a:'a_m_red_',div:'div_m_red_content',ul:'ul_m_red',clickflag:0}
var Movie_new={current:0,step:230,a:'a_m_new_',div:'div_m_new_content',ul:'ul_m_new',clickflag:0}
var TV_red={current:0,step:230,a:'a_tv_red_',div:'div_tv_red_content',ul:'ul_tv_red',clickflag:0}
var TV_new={current:0,step:230,a:'a_tv_new_',div:'div_tv_new_content',ul:'ul_tv_new',clickflag:0}
//综艺首页
var Brand_column={current:0,step:0,a:'a_brand_column_',div:'div_brand_column_content',ul:'ul_brand_column'}

var Turn={}
Turn.pre=function(obj){
	if(obj.current==0){
		return;
	}else{
		Turn.go(obj,obj.current-1);
	}
}
Turn.next=function(obj){
	if(obj.current==2){
		return;
	}else{
		Turn.go(obj,obj.current+1);
	}
}
Turn.go=function(obj,index){
	if(obj.current==index){return;}
	var span=-index+obj.current;
	if(obj.clickflag > 0){return;}
	obj.clickflag=1;
	if(obj.step>0) {
		try {
			//showImage(index) ;
			if (obj.img) {
				setTimeout( function () {
							for (cnt=index*6;cnt<=((index+1)*6 -1 );cnt++ ) {
								var picobj = document.getElementById(obj.div　+ "_pic_" + cnt) ;
								//alert(obj.img[cnt]) ;
								//if (picobj.src == "http://images.movie.xunlei.com/img_default.gif"){
									picobj.src = obj.img[cnt] ;
								//}
							}
						}, 50) ;
			}
		}
		catch (e){}
		ScrollCrossLeft.scroll($(obj.div),obj.step,span,parseInt($(obj.div).style.marginLeft)||0,cb,10);
	}
	else{
		displayNOrY();
		cb();	
	}
	function showImage() {
		for (cnt=index*6;cnt<=((index+1)*6 -1 );cnt++ ) {
			var picobj = document.getElementById(obj.div　+ "_pic_" + cnt) ;
			//alert(obj.img[cnt]) ;
			if (picobj.src == "http://images.movie.xunlei.com/img_default.gif"){
				picobj.src = obj.img[cnt] ;
			}
		}
	}
	function imgSrc(index,id){
		var arr_img=$(id+'_'+index).getElementsByTagName('img');
		for(var i=0;i<6;i++){
			arr_img[i].src=obj.imgs[index-1][i];
		}
	}
	function cb(){
		obj.current=index;
		obj.clickflag=0;
		for(var i=0;i<3;i++){
			$(obj.a+i).className='';
		}
		$(obj.a+index).className='currA';
	}
	function displayNOrY(){
		obj.current=index;
		for(var i=0;i<3;i++){
			if(i==index)
				$(obj.ul+'_'+i).style.display='block';
			else
				$(obj.ul+'_'+i).style.display='none';
		}
	}
}
function xlAjax(url, pars, successFun) {
	var doc = document.getElementById('iframe_proxy').contentWindow;
	return doc.pxlAjax(url,pars,successFun);
}
function showRecommend(response) {
	//alert(eval(response.responseText).length) ;
	var RecommendData = eval(response.responseText);
	var ShowStr = "" ;
	for (i=0;i<RecommendData.length;i++) {
		ShowStr += '<li><a href="'+RecommendData[i]['vod_link']+'" class="playpic" title="点击播放&#13;'+RecommendData[i]['title']+'"><img src="'+RecommendData[i]['poster']+'" /><em></em></a><a href="'+RecommendData[i]['vod_link']+'" title="点击播放&#13;'+RecommendData[i]['title']+'">'+RecommendData[i]['title']+'</a></li>' ;
	}
	document.getElementById("kankan_recom").innerHTML = ShowStr ;
}
function __init__() {
	var ajax = xlAjax("http://movie.xunlei.com/kankan_recommend.php?movieid="+id,"",showRecommend);
	ajax.get();
}
function randomOrder (targetArray) {
	var arrayLength = targetArray.length ;
	var tempArray1 = new Array();
	for (var i = 0; i < arrayLength; i ++) {
		tempArray1 [i] = i ;
	}
	var tempArray2 = new Array();
	for (var i = 0; i < arrayLength; i ++) {
		tempArray2 [i] = tempArray1.splice (Math.floor (Math.random () * tempArray1.length) , 1) ;
	}
	var tempArray3 = new Array();
	for (var i = 0; i < arrayLength; i ++) {
		tempArray3 [i] = targetArray [tempArray2 [i]] ;
	}
	return tempArray3 ;
}
function showBigMovie() {
	var BigMovieshow = randomOrder(BigMovie) ;
	var showHTML = "" ;
	for(i=0;i<6;i++) {
		showHTML += '<li><a href="'+BigMovieshow[i]['link']+'" class="playpic" title="点击播放&#13;'+BigMovieshow[i]['title']+' ('+BigMovieshow[i]['year']+')"><img src="'+BigMovieshow[i]['img']+'"/><em></em></a></li>' ;
	}
	document.getElementById("BigMovieCont").innerHTML = showHTML ;
}
function getParameter(name){
    var search = document.location.search;
    var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
    var matcher = pattern.exec(search);
    var items = null;
    if(null != matcher){
        items = decodeURIComponent(matcher[1]);
        //items = unescape(matcher[1]);
    }
    return items;
}